Conversation
…erts Signed-off-by: mday-io <mdaytn@gmail.com>
Strip the injected virtual catalog from every rendered expression rather than only queries and inserts, so CTAS and DELETE statements no longer leak it. Drop the fallback to the configured virtual_catalog when none was injected, matching the other catalog strip sites, and only copy the expression when a reference actually needs rewriting. Consolidate the tests: the unconfigured-catalog test never enabled the feature, and the fallback test only covered the removed fallback. Signed-off-by: mday-io <mdaytn@gmail.com>
|
@mday-io No blocker from me, but a few things:
|
`execute()` sends string statements verbatim, so the central stripping in `_to_sql` never sees them. `_create_table_like`, `_exchange_tables`, `_rename_table` and the table/column comment builders still sent the injected virtual catalog to ClickHouse. This broke insert-overwrite (incremental model loads) and silently dropped comments. Route those table names through `_strip_virtual_catalog`, and parse string names with the ClickHouse dialect when stripping. `_create_table_like` now renders quoted identifiers, consistent with the rename/exchange statements. Also add a regression test that three-part names are left untouched when no virtual catalog has been injected. Signed-off-by: mday-io <mdaytn@gmail.com>
The INSERT ... SELECT case already covers the same table and column references, and every regression that fails the plain SELECT case also fails it. Signed-off-by: mday-io <mdaytn@gmail.com>
Description
When a ClickHouse gateway is used alongside catalog-aware gateways, SQLMesh injects a virtual catalog (
__<gateway>__by default, or the configuredvirtual_catalog) so every model has a 3-part name. ClickHouse doesn't support catalogs, so that prefix has to be stripped before SQL reaches the engine. Some DDL paths already handled this (create_view,alter_table,delete_from's target table,create_schema), but the queries themselves still carried the catalog. As a result,INSERT ... SELECT,CREATE TABLE ... AS SELECTand subqueries insideDELETE ... WHEREall failed.This PR strips the virtual catalog centrally in
ClickhouseEngineAdapter._to_sql, so it covers every rendered statement:_default_cataloghas its catalog removed.INSERT ... VALUESstatements aren't deep-copied for no reason.inject_virtual_catalog()has run. This matches the existing strip sites, so a ClickHouse-only project withvirtual_catalogconfigured behaves exactly as before.Test Plan
Added to
tests/core/engine_adapter/test_clickhouse.py:test_virtual_catalog_stripped_from_execute_queries(parametrized) covers INSERT ... SELECT, a plain SELECT, and a JOIN that mixes the virtual catalog with another catalog plus a string literal containing the catalog name. It also checks that the input expression isn't mutated.test_virtual_catalog_stripped_from_ctas_and_deletechecks the exact SQL emitted byctas()and bydelete_from()with a subquery.Both tests fail without the fix. All 38 tests in
test_clickhouse.pypass, and so doesruff/mypyon the changed files.Checklist
make styleand fixed any issuesmake fast-test)git commit -s) per the DCO